/*
 *  MouseOverPattern.cpp
 *  Rempart
 *
 *
 */

#include "MouseOverPattern.h"

// sf::Image* RessourcesManager::groundSurface(0)


const int MouseOverPattern::numberOfPattern = 5;
const int MouseOverPattern::patternList[numberOfPattern][3][3] = {
	{
		{0,1,0},
		{0,1,0},
		{0,1,0}
	},
	{
		{0,1,0},
		{1,1,1},
		{0,0,0}
	},
	{
		{0,0,0},
		{0,1,0},
		{0,0,0}
	},
	{
		{1,1,0},
		{0,1,0},
		{0,1,1}
	},
	{
		{0,1,0},
		{0,1,1},
		{0,0,0}
	}
	
};

void MouseOverPattern::initVars(int random){

	
	
	if (random >= numberOfPattern || random < 0) {
		random = sf::Randomizer::Random(0, this->numberOfPattern-1);
	}
	for (int i = 0; i < 3; i++) {
		for (int u = 0; u < 3; u++) {
			this->currentPattern[i][u] = this->patternList[random][i][u];
		}
	}


}

MouseOverPattern::MouseOverPattern(){
	this->initVars(sf::Randomizer::Random(0, this->numberOfPattern-1));
	
}
MouseOverPattern::MouseOverPattern(int myTemplate){
	this->initVars(myTemplate);
}
MouseOverPattern::~MouseOverPattern(){
}
bool MouseOverPattern::isSelected(int case_x,int case_y){
	if (case_x < 0 || case_x > 2) {
		return false;
	}
	else if (case_y < 0 || case_y > 2) {
		return false;
	}
	else{
		return this->currentPattern[case_x][case_y];
	}
}

void MouseOverPattern::rotate(){
	for (int i=0; i<2; ++i){
		bool temp  = this->currentPattern[i][0] ;
		this->currentPattern[i][0] = this->currentPattern[2][i];
		this->currentPattern[2][i] = this->currentPattern[2-i][2];
		this->currentPattern[2-i][2] =this->currentPattern[0][2-i];
		this->currentPattern[0][2-i] = temp;
	}
}